<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!--<head th:replace="_fragments :: head('博客详情')">-->
<!--</head>-->
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title th:text="博客展示">博客展示啊！！！</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
  <link rel="stylesheet" href="../static/css/typo.css" th:href="@{/css/typo.css}">
  <link rel="stylesheet" href="../static/css/animate.css" th:href="@{/css/animate.css}">
  <link rel="stylesheet" href="../static/lib/prism/prism.css" th:href="@{/lib/prism/prism.css}">
  <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css" th:href="@{/lib/tocbot/tocbot.css}">
  <link rel="stylesheet" href="../static/css/me.css" th:href="@{/css/me.css}">

  <!--    // Live2D Widget ：看板娘-->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
  <!--通过浏览器F12的网络来查看加载位置正不正确-->
  <script src="../static/lib/live2d-widget/autoload.js" th:src="@{/lib/live2d-widget/autoload.js}"></script>
  <!-- 随机语句 -->
  <script src="https://v1.hitokoto.cn/?encode=js&select=%23hitokoto" defer></script>
</head>
<body>

  <!--导航-->
  <nav th:replace="_fragments :: menu(0)"></nav>


  <!-- 图片 、 标题-->
  <div class="ui container m-opacity" style="width: 100%">
    <div class="m-bg-type_outer " >
      <img src="../static/images/bg1.jpg" style="width: 100%;height: 220px" th:src="@{${blog.firstPicture}}" alt="" class="ui m-bg image" >
      <div class="m-bg-class_cover">
        <div class="ui container" style="position: relative ;bottom: -620px;">
          <h2 class="m-font-size-title-large" align="center" th:text="${blog.title}">Markdown编辑</h2>
          <div class="ui container" align="center">
            <div class="ui horizontal link list" align="center">
              <div class="item" >
                <div class="ui orange basic label" style="font-size: 7px" th:text="${blog.flag}">原创</div>
              </div>
              <div class="item">
                <i class="user outline icon m-font-size-text-mini"></i>
                <a href="#" style="color: #ffffff;font-size: 15px" th:text="${blog.user.nickname}">ONESTAR</a>
              </div>
              <div class="item ">
                <i class="calendar icon m-font-size-text-mini"></i>
                <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}" class="m-font-size-text-mini">2020-01-01</span>
              </div>
              <div class="item">
                <i class="eye icon m-font-size-text-mini"></i> <span th:text="${blog.views}" class="m-font-size-text-mini">2222</span>
              </div>
              <div class="item">
                <i class="comment outline icon m-font-size-text-mini"></i>
                <span th:text="${blog.commentCount}" class="m-font-size-text-mini">2222</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <!--文章内容 、 联系 、 评论区-->
  <div class="ui container m-opacity-mini">
    <div class="ui stackable grid">
      <div class=" eighteen wide column" style="margin-top: 15px">
        <div id="waypoint" class="m-container-small  animated fadeIn" >
          <div class="ui container">
            <div class="ui padded segment">
              <div id="content" class="typo  typo-selection js-toc-content m-padded-tb-large" th:utext="${blog.content}">

                <h2 id="section1">一、关于 <i class="serif">Typo.css</i></h2>
                <pre><code class="language-css">p { color: red }</code></pre>
                <pre><code class="language-css">p { color: red }</code></pre>
                <p><i class="serif">Typo.css</i> 的目的是，在一致化浏览器排版效果的同时，构建最适合中文阅读的网页排版。</p>
                <h4>现状和如何去做：</h4>
                <p class="typo-first">排版是一个麻烦的问题 <sup><a href="#appendix1"># 附录一</a></sup>，需要精心设计，而这个设计却是常被视觉设计师所忽略的。前端工程师更常看到这样的问题，但不便变更。因为在多个 OS 中的不同浏览器渲染不同，改动需要多的时间做回归测试，所以改变变得更困难。而像我们一般使用的
                  Yahoo、Eric Meyer 和 Alice base.css 中采用的 Reset 都没有很好地考虑中文排版。<i class="serif">Typo.css</i> 要做的就是解决中文排版的问题。</p>
                <p><strong><i class="serif">Typo.css</i> 测试于如下平台：</strong></p>
                <table class="ui table" summary="Typo.css 的测试平台列表">
                  <thead>
                  <tr>
                    <th>OS/浏览器</th>
                    <th>Firefox</th>
                    <th>Chrome</th>
                    <th>Safari</th>
                    <th>Opera</th>
                    <th>IE9</th>
                    <th>IE8</th>
                    <th>IE7</th>
                    <th>IE6</th>
                  </tr>
                  </tbody>
                </table>
                <h4>中文排版的重点和难点</h4>
                <h5 id="appendix2">2、开源许可</h5>
              </div>

              <div class="ui horizontal divider">end</div>
              <!--标签-->
                <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}">方法论</div>

              <!--赞赏-->
              <div class="ui center aligned basic " style="text-align: center">
                <button id="payButton"  class="ui orange right basic circular button">赞赏</button>
              </div>
              <div class="ui payQR flowing popup transition hidden">
                <div class="ui orange basic label">
                  <div class="ui images" style="font-size: inherit !important;">
                    <div class="image">
                      <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt="" class="ui rounded bordered image" style="width: 120px">
                      <div>支付宝</div>
                    </div>
                    <div class="image">
                      <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt="" class="ui rounded bordered image" style="width: 120px">
                      <div>微信</div>
                    </div>
                  </div>
                </div>
              </div>

            </div>
            <div class="ui positive message">
              <!--博客信息-->
              <div class="ui middle aligned grid">
                <div class="eleven wide column">
                  <ui class="list">
                    <li>作者：<span th:text="${blog.user.nickname}">十万</span><a href="#" th:href="@{/about}">（联系作者）</a></li>
                    <li>发表时间：<span th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd HH:mm')}">2017-10-01 10:00</span></li>
                    <li>版权声明：自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
<!--                    <li>公众号转载：请在文末添加作者公众号二维码</li>-->
                  </ui>
                </div>
                <div class="five wide column">
                  <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt="" class="ui right floated rounded bordered image" style="width: 110px">
                </div>
              </div>
            </div>

            <!--留言 -->
            <div th:if="${blog.commentabled}">
              <div  class="ui bottom attached segment" >
                <!--留言区域列表-->
                <div id="comment-container" class="ui teal segment">
                  <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%">
                      <h3 class="ui dividing header">评论区</h3>
                      <!-- 第一条评论 -->
                      <div class="comment" th:each="comment : ${commentLists}">
                        <!-- 评论用户的图片 -->
                        <a class="avatar">
                          <img src="https://unsplash.it/100/100?image=1005" th:src="@{${comment.avatar}}">
                        </a>
                        <!-- 评论用户的信息 -->
                        <div class="content">
                          <!-- 评论用户的昵称 -->
                          <a class="author" >
                            <span th:text="${comment.nickname}">Matt</span>
                            <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.adminComment}">博主</div>
                          </a>
                          <!-- 评论用户的时间 -->
                          <div class="metadata">
                            <!--                            Time: <span th:text="${comment.createTime}"></span>-->
                            <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                          </div>
                          <!-- 评论用户的内容 -->
                          <div class="text" th:text="${comment.content}">
                            How artistic!
                          </div>
                          <!-- 评论用户的回复 -->
                          <div class="actions">
                            <a class="reply" data-commentid="1" data-commentnickname="Mart"
                               th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}"
                               onclick="reply(this)">回复</a>
                          </div>
                        </div>
                        <!-- 子集 -->
                        <!-- 第一条评论的回复评论 -->
                        <div class="comments" th:if="${#arrays.length(comment.replyComments)} > 0">
                          <div class="comment"  th:each="reply : ${comment.replyComments}">
                            <a class="avatar">
                              <img src="https://unsplash.it/100/100?image=1005" th:src="@{${reply.avatar}}">
                            </a>
                            <div class="content" >
                              <a class="author" >
                                <span th:text="${reply.nickname}">Matt</span>
                                <span class="ui m-orange" th:text="| @  ${reply.parentComment.nickname}|">@ 花花</span>
                                <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${reply.adminComment}">博主</div>

                              </a>
                              <div class="metadata">
                                <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">Just now</span>
                              </div>
                              <div class="text" th:text="${reply.content}">
                                Elliot you are always so right :)
                              </div>
                              <div class="actions">
                                <a class="reply"  th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)">回复</a>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                      <!-- 第二条评论 -->
                      <!--/*-->
                      <div class="comment">
                        <a class="avatar">
                          <img src="https://unsplash.it/100/100?image=1005">
                        </a>
                        <div class="content">
                          <a class="author">Elliot Fu</a>
                          <div class="metadata">
                            <span class="date">Yesterday at 12:30AM</span>
                          </div>
                          <div class="text">
                            <p>This has been very useful for my research. Thanks as well!</p>
                          </div>
                          <div class="actions">
                            <a class="reply">回复</a>
                          </div>
                        </div>
                      </div>
                      <!--*/-->
                      <!-- 第三条评论 -->
                      <!--/*-->
                      <div class="comment">
                        <a class="avatar">
                          <img src="https://unsplash.it/100/100?image=1005">
                        </a>
                        <div class="content">
                          <a class="author">Joe Henderson</a>
                          <div class="metadata">
                            <span class="date">5 days ago</span>
                          </div>
                          <div class="text">
                            Dude, this is awesome. Thanks so much
                          </div>
                          <div class="actions">
                            <a class="reply">回复</a>
                          </div>
                        </div>
                      </div>
                      <!--*/-->
                    </div>
                  </div>
                </div>
                <div class="ui form" id="comment-form">

                  <input type="hidden" name="blog.id"th:value="${blog.id}">
                  <input type="hidden" name="parentComment.id" value="-1">

                  <div class="field">
                    <textarea name="content" placeholder="请输入评论信息..."></textarea>
                  </div>
                  <div class="fields">
                    <!--姓名-->
                    <div class="field m-mobile-wide m-margin-bottom-small">
                      <div class="ui left icon input">
                        <i class="user icon"></i>
                        <input type="text" name="nickname" placeholder="姓名" th:value="${session.user_session} !=null ? ${session.user_session.nickname}">
                      </div>
                    </div>
                    <!--邮箱-->
                    <div class="field m-mobile-wide m-margin-bottom-small">
                      <div class="ui left icon input">
                        <i class="mail icon"></i>
                        <input type="text" name="email" placeholder="邮箱" th:value="${session.user_session} !=null ? ${session.user_session.email}">
                      </div>
                    </div>
                    <!--发布-->
                    <div class="field  m-margin-bottom-small m-mobile-wide">
                      <button id="commentpost-btn" class="ui teal button m-mobile-wide"><i class="edit icon"></i>发布</button>
                    </div>
                  </div>
                </div>
              </div>
            </div>

          </div>
        </div>

        <!-- 右下角目录、分享、回到顶部-->
        <div id="toolbar" class="m-padded m-fixed m-right-bottom" style="display: none">
          <div class="ui vertical icon buttons ">
            <button type="button" class="ui toc teal button" >目录</button>
            <a href="#comment-container" class="ui teal button" >评论</a>
            <div id="toTop-button" class="ui icon button" ><i class="chevron up icon"></i></div>
          </div>
        </div>
        <div class="ui toc-container flowing popup transition hidden" style="width: 250px!important;">
          <ol class="js-toc">
          </ol>
        </div>
        <div id="qrcode" class="ui wechat-qr flowing popup transition hidden "style="width: 130px !important;">
        </div>
          <!-- 右下角目录、分享、回到顶部 -->
      </div>
    </div>
  </div>

  <!--底部footer-->
  <footer th:replace="_fragments :: footer"></footer>

  <!-- 导入的script -->
  <th:block th:replace="_fragments :: script">
  </th:block>


  <script th:inline="javascript">

    $('.menu.toggle').click(function () {
      $('.m-item').toggleClass('m-mobile-hide');
    });

    $('#payButton').popup({
      popup : $('.payQR.popup'),
      on : 'click',
      position: 'bottom center'
    });

    tocbot.init({
      // Where to render the table of contents.
      tocSelector: '.js-toc',
      // Where to grab the headings to build the table of contents.
      contentSelector: '.js-toc-content',
      // Which headings to grab inside of the contentSelector element.
      headingSelector: 'h1, h2, h3',
    });

    $('.toc.button').popup({
      popup : $('.toc-container.popup'),
      on : 'click',
      position: 'left center'
    });

    $('.wechat').popup({
      popup : $('.wechat-qr'),
      position: 'left center'
    });


    var serUrl = 'http://localhost:8080'; // 指定域名
    var url = /*[@{/blog/{id}(id=${blog.id}})]*/"";
    var qrcode = new QRCode("qrcode", {
      text: url,
      width: 110,
      height: 110,
      colorDark : "#000000",
      colorLight : "#ffffff",
      correctLevel : QRCode.CorrectLevel.H
    });
    
    $('#toTop-button').click(function () {
      $(window).scrollTo(0,500);
    });

    var waypoint = new Waypoint({
      element: document.getElementById('waypoint'),
      handler: function(direction) {
        if (direction == 'down') {
          $('#toolbar').show(100);
        } else {
          $('#toolbar').hide(500);
        }
        console.log('Scrolled to waypoint!  ' + direction);
      }
    });


    /*  评论   */
    //评论表单验证
    $('.ui.form').form({
      fields: {
        content: {
          identifier: 'content',
          rules: [{
            type: 'empty',
            prompt: '请输入评论内容'
          }
          ]
        },
        nickname: {
          identifier: 'nickname',
          rules: [{
            type: 'empty',
            prompt: '请输入你的大名'
          }]
        },
        email: {
          identifier: 'email',
          rules: [{
            type: 'email',
            prompt: '请填写正确的邮箱地址'
          }]
        }
      }
    });


    // 页面完成后, 加载评论
    $(function(){
      $("#comment-container").load(/*[[@{/comments/{blogId}(blogId=${blog.id})}]]*/"comments/6");
    });

    // 点击按钮，校验表单并提交
    $('#commentpost-btn').click(function () {
      var boo = $('.ui.form').form('validate form');
      if (boo) {
        console.log('校验成功');
        postData();
      } else {
        console.log('校验失败');
      }
    });


    /*
    * load(url,data,function(response,status,xhr))
    * url：地址
    * data：数据
    * function()：回调函数
    * */
    // 需要提交的参数
    function postData() {
      $("#comment-container").load("/comments",{
        "parentComment.id" : $("[name='parentComment.id']").val(),
        "blog.id" : $("[name='blog.id']").val(),
        "nickname": $("[name='nickname']").val(),
        "email"   : $("[name='email']").val(),
        "content" : $("[name='content']").val()
      },function (responseTxt, statusTxt, xhr) {
        $(window).scrollTo($('#goto'),500);
        clearContent();
      });
    }

    // 清除输入的评论、姓名、邮箱
    function clearContent() {
      $("[name='nickname']").val('');
      $("[name='email']").val('');
      $("[name='content']").val('');
      $("[name='parentComment.id']").val(-1);
      $("[name='content']").attr("placeholder", "请输入评论信息...");
    }

    // 回复时：要获取回复对象的 id 和 昵称
    function reply(obj) {
      var commentId = $(obj).data('commentid');
      var commentNickname = $(obj).data('commentnickname');
      // alert(commentId + " ------- " + commentNickname);
      /*内容就是：@ + 要回复的昵称 + 输入的内容*/
      $("[name='content']").attr("placeholder", "@"+commentNickname).focus();
      /*回复别人，所以 父评论id = 获取的被回复的id*/
      $("[name='parentComment.id']").val(commentId);
      $(window).scrollTo($('#comment-form'),500);
    }

  </script>
</body>
</html>